package com.qf.demo;

import com.qf.dao.AccountDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AccountTest {
    public static void main(String[] args) {
//        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean.xml");

//        //如何把bean变成多例
//        AccountDao accountDao = (AccountDao) applicationContext.getBean("accountDao");
//        AccountDao accountDao1 = (AccountDao) applicationContext.getBean("accountDao");
//        AccountDao accountDao2 = (AccountDao) applicationContext.getBean("accountDao");
//
//        System.out.println(accountDao);
//        System.out.println(accountDao1);
//        System.out.println(accountDao2);
//        System.out.println(accountDao==accountDao1);
//        System.out.println(accountDao1==accountDao2);
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean.xml");
        AccountDao accountDao = (AccountDao) applicationContext.getBean("accountDao");
        accountDao.addAccount();
        System.out.println(accountDao);

        ((ClassPathXmlApplicationContext) applicationContext).close();
    }
}
